package com.zjw.dao.impl;

import com.zjw.dao.BaseDao;
import com.zjw.dao.ResultDao;
import com.zjw.utils.ConnectionUtil;
import com.zjw.vo.StudentResultVo;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/**
 * @projectName: studentCourseSelectionManagement
 * @package: com.zjw.dao.impl
 * @className: ResultDaoImpl
 * @author: 翟
 * @date: 2025/4/7 1:16
 */

public class ResultDaoImpl extends BaseDao implements ResultDao {
    public ResultDaoImpl(Connection connection) {
        super(connection);
    }

    @Override
    public List<StudentResultVo> selectResultByStudentId(int studentNo) throws SQLException {
        String sql = "SELECT `student`.`StudentName` , `SubjectNo` , `StudentResult` , `ExamDate` FROM `result`\n" +
                "INNER JOIN `student` ON `student`.`StudentNo` = `result`.`StudentNo`\n" +
                "WHERE `student`.`StudentNo` = ?";
        ResultSet resultSet = null;
        List<StudentResultVo> list = null;
        try {
            resultSet = executeQuery(sql , studentNo);
            list = new ArrayList<>();
            while (resultSet.next()){
                StudentResultVo studentResultVo = new StudentResultVo();
                studentResultVo.setStudentName(resultSet.getString("StudentName"));
                studentResultVo.setSubjectNo(resultSet.getInt("SubjectNo"));
                studentResultVo.setStudentResult(resultSet.getInt("StudentResult"));
                studentResultVo.setExamDate(resultSet.getDate("ExamDate"));
                list.add(studentResultVo);
            }
        } finally {
            ConnectionUtil.closeALL(resultSet , null , null);
        }
        return list;
    }


}
